#pragma once

struct DSAOutput{
	//unsigned int region;
	//std::complex<double> *out;

	std::vector< int > eids;
	unsigned int  startpt;
	unsigned int endpt;
	double max;
	std::vector< std::vector<double> >  data;
	int signiture;

	DSAOutput():data(0){}
	~DSAOutput(){
	}

//	void release(){ if(data) delete data;}

};


struct DSA_CalcParams{
	std::vector< int> eids ;
	unsigned int startpt;
	unsigned int endpt;
	int signiture;
};
 

class DSACalculator
{
	static DSACalculator *instance;
	DSACalculator(void);
	bool isOutputReady;
	std::vector<DSAOutput*> out;
	const DataStore *source;
	CWaitBoxDlg wbd;
	void DoCalc(const DSA_CalcParams p);//calc the DSA of the n-th ch.
	friend void DSA_Working_Thread( LPVOID );
public:
	~DSACalculator(void);
	static DSACalculator *GetInstance(){
		if(!instance)
			instance = new DSACalculator();
		return instance;
	}

	static void DestoryInstance(){
		if(instance)
			delete instance;
	}

//	int EID2Index(int eid);
//	int Index2EID(UINT index){if(index>=out.size()) return -1; return out[index].eid;};
	const std::vector<DSAOutput*> GetOutputs() const{return out;}
	const DataStore* GetSource() const {return source;}
	size_t GetOutputCount(){ return out.size();}
	bool isReady(){ return isOutputReady;};
	//void SetSource(const DataStore *s){source = s;}
	void reset(){ isOutputReady = false; ClearOutput();}
	void ClearOutput(){ 
		for(size_t i=0;i<out.size();i++)
			if(out[i])
				delete out[i];
		out.clear(); 
	}
	int StartCalc( DSA_CalcParams p);

	bool Export2File(LPCTSTR filename, int eid);
	int FindInOut(int signiture) const ;
};
